/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.pay.merchant.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.pay.merchant.entity.MerchantDetails;
import com.jeesite.modules.kj.pay.merchant.service.MerchantDetailsService;

/**
 * merchant_detailsController
 * @author hzy
 * @version 2019-11-22
 */
@Controller
@RequestMapping(value = "${adminPath}/merchant/merchantDetails")
public class MerchantDetailsController extends BaseController {

	@Autowired
	private MerchantDetailsService merchantDetailsService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public MerchantDetails get(String detailsId, boolean isNewRecord) {
		return merchantDetailsService.get(detailsId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("merchant:merchantDetails:view")
	@RequestMapping(value = {"list", ""})
	public String list(MerchantDetails merchantDetails, Model model) {
		model.addAttribute("merchantDetails", merchantDetails);
		return "pay/merchant/merchantDetailsList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("merchant:merchantDetails:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<MerchantDetails> listData(MerchantDetails merchantDetails, HttpServletRequest request, HttpServletResponse response) {
		merchantDetails.setPage(new Page<>(request, response));
		Page<MerchantDetails> page = merchantDetailsService.findPage(merchantDetails);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("merchant:merchantDetails:view")
	@RequestMapping(value = "form")
	public String form(MerchantDetails merchantDetails, Model model) {
		model.addAttribute("merchantDetails", merchantDetails);
		return "pay/merchant/merchantDetailsForm";
	}

	/**
	 * 保存merchant_details
	 */
	@RequiresPermissions("merchant:merchantDetails:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated MerchantDetails merchantDetails) {
		merchantDetailsService.save(merchantDetails);
		return renderResult(Global.TRUE, text("保存merchant_details成功！"));
	}
	
	/**
	 * 停用merchant_details
	 */
	@RequiresPermissions("merchant:merchantDetails:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(MerchantDetails merchantDetails) {
		merchantDetails.setStatus(MerchantDetails.STATUS_DISABLE);
		merchantDetailsService.updateStatus(merchantDetails);
		return renderResult(Global.TRUE, text("停用merchant_details成功"));
	}
	
	/**
	 * 启用merchant_details
	 */
	@RequiresPermissions("merchant:merchantDetails:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(MerchantDetails merchantDetails) {
		merchantDetails.setStatus(MerchantDetails.STATUS_NORMAL);
		merchantDetailsService.updateStatus(merchantDetails);
		return renderResult(Global.TRUE, text("启用merchant_details成功"));
	}
	
	/**
	 * 删除merchant_details
	 */
	@RequiresPermissions("merchant:merchantDetails:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(MerchantDetails merchantDetails) {
		merchantDetailsService.delete(merchantDetails);
		return renderResult(Global.TRUE, text("删除merchant_details成功！"));
	}
	
}